const { app, BrowserWindow, screen } = require('electron');
const path = require("path");
// 尝试获取单实例锁
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
  // 如果没有获取到锁，说明已经有一个实例在运行，直接退出当前实例
  app.quit();
} else {
  let mainWindow;
  function createWindow() {
    const { width, height } = screen.getPrimaryDisplay().workAreaSize
    mainWindow = new BrowserWindow({
      width: Math.ceil(width * 1),
      height: Math.ceil(height * 1),
      icon: path.join(__dirname, 'logo.png'),
      autoHideMenuBar: true,
      fullscreenable: false,
      webPreferences: {
        nodeIntegration: true,
        contextIsolation: false
      }
    });
    mainWindow.maximize();
    const indexPath = path.join(__dirname, "dist/index.html")
    mainWindow.loadFile(indexPath);
    // mainWindow.loadURL('http://localhost:5173');
    // mainWindow.webContents.openDevTools({ mode: 'detach' }) //打开控制台
    
  }

  app.whenReady().then(() => {
    createWindow();
  });
}
